#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/1/24 10:19
# @Author  : Aries
# @Site    : 
# @File    : login.py
# @Software: PyCharm
# import sys
# import  os
import time
import unittest
import warnings

from macaca import WebDriver

from data import base_data
from drivers.wd import desired_caps, server_url
from src.page.login_page import LoginPage
from data import base_xpath
from utils.HTMLTestRunner import HTMLTestRunner

warnings.simplefilter(action='error', category=ResourceWarning)

class LoginTest(unittest.TestCase):
    def setUp(self):
        self.driver = WebDriver(desired_caps, server_url)
        self.driver.init()

    def test_loginSucess(self):
        self.LP = LoginPage()
        self.LP.loginAction(self.driver,base_data.user['user_zdd']['username'],base_data.user['user_zdd']['password'])
        time.sleep(5)
        self.assertFalse(self.driver.element_if_exists('xpath',base_xpath.loginButton))

    def test_loginFailed(self):
        self.LP = LoginPage()
        self.LP.loginAction(self.driver,'XXX','123456')
        time.sleep(5)
        self.assertTrue(self.driver.element_if_exists('xpath',base_xpath.loginButton))

    def tearDown(self):
        self.driver.quit()


# if __name__ == '__main__':
#     suite = unittest.TestSuite()
#     suite.addTest(LoginTest("test_login"))
#     now = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
#     filename = "E:/WorkSpace/dgt_UIAutoTest/report/"+now + "test.html"
#     print(filename)
#     fp = open(filename, "wb")
#     runner = HTMLTestRunner(stream=fp, title=u"店管通UI自动化测试", description=u"用例执行情况")
#     runner.run(suite)
#     fp.close()

# def suite():
#     suite=unittest.TestSuite()
#     suite.addTest(LoginTest('test_login'))
#     return suite
